﻿namespace ExceptionsHandling
{
    using System;

    class MethodWithExceptions
    {
        // 1.2.11.02. Write a method ReadNumber(int start, int end) that enters an integer number in given
        // range [start…end]. If an invalid number or non-number text is entered, the method should
        // throw an exception. Using this method write a program that enters 10 numbers:
        // a1, a2, … a10, such that 1 < a1 < … < a10 < 100

        public static int ReadNumber(int start, int end)
        {
            string numInput = Console.ReadLine();

            try
            {
                int.Parse(numInput);
            }
            catch (FormatException)
            {
                throw new FormatException("There is no way to mess my program.");
            }

            if (int.Parse(numInput) < start || int.Parse(numInput) > end)
            {
                throw new ArgumentOutOfRangeException(String.Format("The number must be ({0} < your number < {1}).", start, end));
            }

            return int.Parse(numInput);
        }

        static void Main()
        {
            int min = 1;
            int max = 100;
            int asdf = ReadNumber(min, max);
            for (int i = 0; i < 9; i++)
            {
                asdf = ReadNumber(asdf, max);
            }
        }
    }
}